import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/entities/setting_data_entity.dart';
import 'package:finance_app/src/widgets/form/form_edit_status_inherited_widget.dart';
import 'package:flutter/material.dart';

class CategoryGstAmountFormItem extends StatelessWidget {
  final SettingDataCategory category;
  final SettingDataTax tax;
  final String amount;
  final bool hasError;
  final bool showHeader;
  final Border border;

  const CategoryGstAmountFormItem(
      {Key key,
      this.hasError = false,
      this.showHeader = false,
      this.category,
      this.tax,
      this.amount,
      this.border = const Border(
          bottom: BorderSide(
        color: aceGrayColor,
        width: 0.5,
      ))})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: Colors.white, border: border),
      padding: EdgeInsets.symmetric(horizontal: getDp(35), vertical: getDp(10)),
      child: Row(
        children: [
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                if (showHeader)
                  Padding(
                    padding: EdgeInsets.only(
                      bottom: getDp(10),
                    ),
                    child: Text(
                      S.current.category,
                      style: TextStyle(
                        color: aceDarkGrayColor,
                        fontSize: getSp(14),
                        fontWeight: FontWeight.w400,
                        height: 1,
                      ),
                    ),
                  ),
                Text(
                  category.name,
                  style: FormEditStatusInheritedWidget.ofStyle(context),
                )
              ],
            ),
          ),
          if (showHeader && Config.currentCompany.enableGst == 1)
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Padding(
                  padding: EdgeInsets.only(
                    bottom: getDp(10),
                  ),
                  child: Text(
                    S.current.gst_rate,
                    style: TextStyle(
                      color: aceDarkGrayColor,
                      fontSize: getSp(14),
                      fontWeight: FontWeight.w400,
                      height: 1,
                    ),
                  ),
                ),
                Container(
                  constraints: BoxConstraints(
                    minWidth: getDp(60),
                  ),
                  child: Text(
                    '${tax?.rate}% ${tax?.key}',
                    style: TextStyle(
                      color: hasError
                          ? aceRedColor
                          : FormEditStatusInheritedWidget.ofEnable(context)
                              ? aceBlueColor
                              : aceBlackColor,
                      fontSize: getSp(18),
                      fontWeight: FontWeight.w700,
                      height: 14 / 18,
                    ),
                  ),
                )
              ],
            ),
          SizedBox(
            width: getDp(16),
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              if (showHeader)
                Padding(
                  padding: EdgeInsets.only(
                    bottom: getDp(10),
                  ),
                  child: Text(
                    S.current.amount,
                    style: TextStyle(
                      color: aceDarkGrayColor,
                      fontSize: getSp(14),
                      fontWeight: FontWeight.w400,
                      height: 1,
                    ),
                  ),
                ),
              Container(
                constraints: BoxConstraints(
                  minWidth: getDp(60),
                ),
                child: Text(
                  '$amount',
                  style: TextStyle(
                    color: hasError
                        ? aceRedColor
                        : FormEditStatusInheritedWidget.ofEnable(context)
                            ? aceBlueColor
                            : aceBlackColor,
                    fontSize: getSp(18),
                    fontWeight: FontWeight.w700,
                    height: 14 / 18,
                  ),
                  textAlign: TextAlign.end,
                ),
              )
            ],
          ),
        ],
      ),
    );
  }
}
